<%--
  Created by IntelliJ IDEA.
  User: HAN
  Date: 2020/11/30
  Time: 10:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery-1.9.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<style>
    #left {
        width: 52%;
        height: 450px;
        border: 1px solid red;
        float: left;
    }

    #refresh {
        float: left;
        width: 2%;
    }

    #right {
        border: 1px solid blue;
        width: 45%;
        height: 450px;
        float: right;
    }
</style>
<body>
<%--<p onclick="refresh()" class="layui-icon layui-icon-refresh layui-anim layui-anim-scaleSpring"></p>--%>

<%--搜索条件表单--%>
<%--<form class="layui-form" id="searchForm">
    <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="year" id="year" placeholder="年份" class="layui-input">
            </div>
            <label class="layui-form-label">范围</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="monthMin" id="month1" placeholder="起始月" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="monthMax" id="month2" placeholder="结束月" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-input-inline" style="width: 50px;">
                <button type="button" onclick="getData()"
                        class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">搜索
                </button>
            </div>
            <div class="layui-input-inline" style="width: 50px;">
                <button type="reset" onclick="refresh()" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary" id="hah">重置
                </button>
            </div>
        </div>
    </div>
</form>--%>


    <div id="left"></div>
    <div id="right"></div>


<script type="text/javascript">
    $(function (){
        getData();

    })

    // 页面刷新按钮
  /*  function refresh(){
        $("#searchForm")[0].reset()
        getData();
    }*/

    // 基于准备好的dom，初始化echarts实例
    var ruKuMoney = [];
    var monthData = [];
    //var ckMoney = []
    function getData(){
        $.ajax({
            url: '/zongji/getZong',
            type: 'post',
            //data: $("#searchForm").serialize(),
            async: false,
            //dataType: 'json',
            success: function (result) {
                ruKuMoney = result.ruKuMoney;
                monthData = result.monthData;
                //ckMoney = result.ckMoney;
                begin();
            }
        })
    }

    function begin() {
        var myChart = echarts.init(document.getElementById('left'));

        // 指定图表的配置项和数据
        var option = {
            color: ['#3398DB'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data:monthData,
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '月份金额',
                    type: 'bar',
                    barWidth: '60%',
                    data:ruKuMoney,
                }
            ]
        };
        myChart.setOption(option)

        var sdata = [];
        $.ajax({
            url: '/zongji/gettype',
            type: 'post',
            async: false,
            dataType: 'JSON',
            success: function (result) {
                alert(typeof result)
                alert(JSON.stringify(result))
                sdata=result;
            },error:function (msg) {
                alert("错误")
            }
        });
        alert(JSON.stringify(sdata))
        var myChart2 = echarts.init(document.getElementById('right'));
        var option2 = {
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                left: 10,
                data:sdata,
            },
            series: [
                {
                    name: '房间类型',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        label: {
                            show: true,
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    },
                    labelLine: {
                        show: false
                    },
                    data: sdata/**[
                        {value: 335, name: '直接访问'},
                        {value: 310, name: '邮件营销'},
                        {value: 234, name: '联盟广告'},
                        {value: 135, name: '视频广告'},
                        {value: 1548, name: '搜索引擎'}
                    ]*!/*/
                }
            ]
        };
        myChart2.setOption(option2);

    }
</script>

<%--时间选择器--%>
<script>
   layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#year' //指定元素
            , type: 'year'
            , calendar: true
        });
        laydate.render({
            elem: '#month1' //指定元素
            , format: 'MM'
            , type: 'month'
            , calendar: true
        });
        laydate.render({
            elem: '#month2' //指定元素
            , format: 'MM'
            , type: 'month'
            , calendar: true
        });
    });
</script>
</body>
</html>
